package com.xayy.mgt.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.kawins.base.result.CheckResult;
import cn.kawins.base.utils.BeanUtil;
import cn.kawins.base.utils.CollUtil;
import cn.kawins.base.utils.StringUtil;
import cn.kawins.base.utils.TreeUtil;
import cn.kawins.mybatis.base.BaseServiceImpl;
import com.xayy.core.antlr4.enums.ValueTypeEnum;
import com.xayy.core.antlr4.model.ErrorResult;
import com.xayy.core.antlr4.utils.FunUtil;
import com.xayy.core.antlr4.utils.Golabl;
import com.xayy.core.antlr4.visitor.HealthEvaluateVisitor;
import com.xayy.mgt.enums.HealthStatu;
import com.xayy.mgt.mapper.HealthSituationMapper;
import com.xayy.mgt.model.*;
import com.xayy.mgt.model.vo.*;
import com.xayy.mgt.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.time.Duration;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Nie
 * @version V1.0
 * @date 2023/8/17 11:46
 */
@Service
public class HealthSituationServiceImpl extends BaseServiceImpl<HealthSituation> implements HealthSituationService {
    @Autowired
    private HistoryFaultService historyFaultService;

    @Autowired
    private FunctionalIndicatorsService functionalIndicatorsService;

    @Autowired
    private PerformanceIndicatorsService performanceIndicatorsService;

    @Autowired
    private HealthDeepService healthDeepService;
    @Autowired
    private NodeInfoService nodeInfoService;
    @Autowired
    private HistoryInfluenceService historyInfluenceService;

    @Autowired
    private HealthSituationMapper healthSituationMapper;

    @Override
    public CheckResult<?> evaluation(EvaluationVo evaluationVo) {
        // 计算前清理缓存
        Golabl.clear(evaluationVo.getSatelliteId());
        HealthDeep healthDeep =
            healthDeepService.selectOne(HealthDeep.builder().nodeId(evaluationVo.getNodeId()).build());
        if (BeanUtil.isEmpty(healthDeep)) {
            return CheckResult.fail("评估节点没有构建评估体系，请去评估体系构建模块配置该节点评估信息");
        }
        String customParam = healthDeep.getCustomParam();
        if (StrUtil.isBlank(customParam)) {
            return CheckResult.fail("评估节点没有构建评估体系，请去评估体系构建模块配置该节点评估信息");
        }

        // 获取节点构建指标的算法相关信息，目前假设门限阈值为0-1，
        List<Double> tempList = new ArrayList<>();
        tempList.add(0d);
        tempList.add(0.1);
        tempList.add(1.6);
        tempList.add(0.6);
        tempList.add(0.4);
        tempList.add(0.67);
        tempList.add(6.7);
        // 计算tempList中值在0-1范围内的数据数量
        int count = (int) tempList.stream().filter(item -> item > 0 && item < 1).count();
        double percent = (double) count / tempList.size();

        // 写一个执行groovy脚本的方法
        String groovyScript = "";





        // 计算正常情况下的健康度指标
        ErrorResult execute = FunUtil.execute(customParam, new HealthEvaluateVisitor(evaluationVo.getSatelliteId(),
            evaluationVo.getNodeId(), evaluationVo.getEvaluationTime(), false, false));
        if (execute.isSuccess()) {
            Double result = execute.getResult();
            // 计算有故障时候的健康度，卫星在轨时间到评估时刻做整个评估时间段，故障时长为该故障下的健康度所在比重，结合起来
            CheckResult<Map<String, Double>> mapCheckResult = errorEvaluation(customParam, evaluationVo);
            if (mapCheckResult.isSuccess()) {
                Double weight = mapCheckResult.getData().get("weight");
                Double score = mapCheckResult.getData().get("score");
                result = weight * result + score;
            }

            // 将数据存库
            insertInfo(evaluationVo.getNodeId(), evaluationVo.getEvaluationTime(), result, healthDeep);
            return CheckResult.success(result);
        }
        int code = execute.getCode();
        List<String> gramErrList = execute.getGramErrList();
        return CheckResult.fail(code, gramErrList.toString());
    }

    @Override
    public CheckResult<Map<String, Double>> errorEvaluation(String customParam, EvaluationVo evaluationVo) {
        Map<String, Double> result = new HashMap<>(2);
        double resultWeight = 1D;
        double resultScore = 0D;
        result.put("weight", resultWeight);
        result.put("score", resultScore);
        // 查询卫星的入轨时间
        NodeTreeInfo nodeTreeInfo = nodeInfoService.selectById(evaluationVo.getSatelliteId());
        Date injectingTime = nodeTreeInfo.getInjectingTime();
        // 计算评估时间段，分钟
        Duration duration = Duration.between(injectingTime.toInstant(), evaluationVo.getEvaluationTime().toInstant());
        long millis = duration.toMillis();
        // 查询入轨时间到评估时刻该节点的历史故障，排除常驻故障
        Example example = new Example(HistoryFault.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("satelliteId", evaluationVo.getSatelliteId());
        criteria.andEqualTo("nodeId", evaluationVo.getNodeId());
        criteria.andNotEqualTo("persistenceTime", "常驻");
        criteria.andBetween("exceptionTime", injectingTime, evaluationVo.getEvaluationTime());
        List<HistoryFault> historyFaults = historyFaultService.selectByExample(example);
        if (CollUtil.isNotEmpty(historyFaults)) {
            for (HistoryFault x : historyFaults) {
                String persistenceTime = x.getPersistenceTime();
                double aDouble = Double.parseDouble(persistenceTime);
                // 故障权重
                double weight = aDouble / millis;
                // 获取故障影响
                List<HistoryInfluence> funList =
                        historyInfluenceService.select(HistoryInfluence.builder().faultId(x.getId()).categories(1).build());
                if (CollUtil.isNotEmpty(funList)) {
                    funList.forEach(fun -> Golabl.setErrorValue(evaluationVo.getSatelliteId(), evaluationVo.getNodeId(),
                            fun.getMetricsCode(), Double.valueOf(fun.getResult()) * 100D, ValueTypeEnum.GN_VALUES.getKey()));
                }
                List<HistoryInfluence> perList =
                        historyInfluenceService.select(HistoryInfluence.builder().faultId(x.getId()).categories(2).build());
                if (CollUtil.isNotEmpty(perList)) {
                    perList.forEach(per -> Golabl.setErrorValue(evaluationVo.getSatelliteId(), evaluationVo.getNodeId(),
                            per.getMetricsCode(), per.getScore(), ValueTypeEnum.XN_VALUES.getKey()));

                }
                // 计算分值
                ErrorResult execute = FunUtil.execute(customParam, new HealthEvaluateVisitor(evaluationVo.getSatelliteId(),
                        evaluationVo.getNodeId(), evaluationVo.getEvaluationTime(), false, true));
                if (execute.isSuccess()) {
                    Double score = execute.getResult();
                    resultWeight -= weight;
                    resultScore += score * weight;
                }
            }
            result.put("weight", resultWeight);
            result.put("score", resultScore);
        }

        return CheckResult.success(result);
    }

    @Override
    public CheckResult<Object> getHealthDeepInfo(Long nodeId) {
        NodeTreeInfo nodeTreeInfo = nodeInfoService.selectById(nodeId);
        if (BeanUtil.isEmpty(nodeTreeInfo)) {
            return CheckResult.fail("未获取到节点信息");
        }
        HealthSituationVo healthSituationVo = new HealthSituationVo();
        healthSituationVo.setNodeId(nodeId);
        healthSituationVo.setSatelliteId(nodeTreeInfo.getSatelliteId());
        healthSituationVo.setNodeName(nodeTreeInfo.getNodeName());
        List<Map<String, String>> values = new ArrayList<>();
        HealthDeep healthDeep = healthDeepService.getHealthDeep(nodeId).getData();
        Map<String, String> healthStatus = new HashMap<>(2);
        if (BeanUtil.isNotEmpty(healthDeep)) {
            Map<String, String> map = new HashMap<>(2);
            map.put("name", "健康指标(" + healthDeep.getMetricsName() + ")");
            map.put("dataInfo", healthDeep.getDataInfo());
            values.add(map);
            healthStatus.put("name", "健康状态");
            if(StringUtil.isNotBlank(healthDeep.getDataInfo())){
                healthStatus.put("dataInfo", HealthStatu.valueof(Double.parseDouble(healthDeep.getDataInfo())) );
            }else{
                healthStatus.put("dataInfo", "暂无数据");
            }
        }

        List<FunctionalIndicators> functionalIndicators =
            functionalIndicatorsService.getFunctionalIndicators(nodeId).getData();
        if (CollUtil.isNotEmpty(functionalIndicators)) {
            functionalIndicators.forEach(x -> {
                Map<String, String> map = new HashMap<>(2);
                map.put("name", "功能项指标(" + x.getMetricsName() + ")");
                map.put("dataInfo", x.getDataInfo());
                values.add(map);
            });
        }

        List<PerformanceIndicators> performanceIndicators =
            performanceIndicatorsService.getPerformanceIndicators(nodeId).getData();
        if (CollUtil.isNotEmpty(performanceIndicators)) {
            performanceIndicators.forEach(x -> {
                Map<String, String> map = new HashMap<>(2);
                map.put("name", "性能项指标(" + x.getMetricsName() + ")");
                map.put("dataInfo", x.getDataInfo());
                values.add(map);
            });
        }

        List<HistoryFault> historyFaults = historyFaultService.select(HistoryFault.builder().nodeId(nodeId).build());
        if (CollUtil.isNotEmpty(historyFaults)) {
            historyFaults.forEach(x -> {
                Map<String, String> map = new HashMap<>(2);
                map.put("name", "异常(" + x.getExceptionName() + ")");
                map.put("dataInfo", x.getPersistenceTime());
                values.add(map);
            });
        }
        if(!healthStatus.isEmpty()){
            values.add(0,healthStatus);
        }
        healthSituationVo.setValues(values);
        return CheckResult.success(healthSituationVo);
    }



    @Override
    public CheckResult<Object> getHealthSituationInfo(Long nodeId,Date time) {
        NodeTreeInfo nodeTreeInfo = nodeInfoService.selectById(nodeId);
        if (nodeTreeInfo == null) {
            return CheckResult.fail("未获取到节点信息");
        }
        HealthSituationVo healthSituationVo = new HealthSituationVo();
        healthSituationVo.setNodeId(nodeId);
        healthSituationVo.setSatelliteId(nodeTreeInfo.getSatelliteId());
        healthSituationVo.setNodeName(nodeTreeInfo.getNodeName());
        List<Map<String, String>> values = new ArrayList<>();
        HealthSituation healthSituation = healthSituationMapper.selectNewHealthData(nodeId,time,"3");
        Map<String, String> healthStatus = new HashMap<>(3);
        if (healthSituation != null) {
            Map<String, String> map = new HashMap<>(3);
            map.put("name", "健康指标(" + healthSituation.getMetricsName() + ")");
            map.put("dataInfo", healthSituation.getDataInfo());
            values.add(map);
            healthStatus.put("name", "健康状态");
            if(StringUtil.isNotBlank(healthSituation.getDataInfo())){
                healthStatus.put("dataInfo", HealthStatu.valueof(Double.parseDouble(healthSituation.getDataInfo())) );
            }else{
                healthStatus.put("dataInfo", "暂无数据");
            }
        }

        HealthSituation gnSituation = healthSituationMapper.selectNewHealthData(nodeId,time,"1");
        if (BeanUtil.isNotEmpty(gnSituation)) {
            Map<String, String> map = new HashMap<>(2);
            map.put("name", "功能项指标(" + gnSituation.getMetricsName() + ")");
            map.put("dataInfo", gnSituation.getDataInfo());
            values.add(map);
        }

        HealthSituation xnSituation = healthSituationMapper.selectNewHealthData(nodeId,time,"2");
        if (BeanUtil.isNotEmpty(xnSituation)) {
            Map<String, String> map = new HashMap<>(2);
            map.put("name", "性能项指标(" + xnSituation.getMetricsName() + ")");
            map.put("dataInfo", xnSituation.getDataInfo());
            values.add(map);
        }

        List<HistoryFault> historyFaults = historyFaultService.select(HistoryFault.builder().nodeId(nodeId).exceptionTime(time).build());
        if (CollUtil.isNotEmpty(historyFaults)) {
            historyFaults.forEach(x -> {
                Map<String, String> map = new HashMap<>(2);
                map.put("dataInfo", x.getPersistenceTime());
                map.put("name", "异常(" + x.getExceptionName() + ")");
                values.add(map);
            });
        }
        if(!healthStatus.isEmpty()){
            values.add(0,healthStatus);
        }
        healthSituationVo.setValues(values);
        return CheckResult.success(healthSituationVo);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void generateHealthReportForWord(WordReportVo wordReportVo) {
        CheckResult<Object> objectCheckResult = generateHealthReport(wordReportVo.getNodeId());
        if(objectCheckResult.ok()){
            Map<String,Object> map = (Map<String,Object>) objectCheckResult.getData();
            /*获取表格信息*/
            List<HealthReportVo> tableList =  (List<HealthReportVo> )map.get("tableList");
        }
    }


    @Override
    public CheckResult<Object> getIndexCurveData(Long nodeId) {
        CurveVo curveVo = new CurveVo();
        List<HealthSituation> list = select(HealthSituation.builder().nodeId(nodeId).build());
        Map<Long, List<HealthSituation>> map =
            list.stream().collect(Collectors.groupingBy(HealthSituation::getMetricsId));
        HealthDeep healthDeep = healthDeepService.getHealthDeep(nodeId).getData();
        healthCurve(healthDeep, curveVo, map);

        List<FunctionalIndicators> functionalIndicators =
            functionalIndicatorsService.getFunctionalIndicators(nodeId).getData();
        functionalCurve(functionalIndicators, curveVo, map);

        List<PerformanceIndicators> performanceIndicators =
            performanceIndicatorsService.getPerformanceIndicators(nodeId).getData();
        performanceCurve(performanceIndicators, curveVo, map);
        return CheckResult.success(curveVo);
    }

    @Override
    public CheckResult<Object> generateHealthReport(Long nodeId) {
        /*查询节点数*/
        CheckResult<Object> nodeTree = nodeInfoService.getNodeTree(nodeId);
        if(nodeTree.ok() && nodeTree.getData() != null){
            /*查询每个节点的分值*/
            NodeTreeInfoVo data = (NodeTreeInfoVo)nodeTree.getData();
            List<NodeTreeInfoVo> nodeTreeInfoVos = TreeUtil.toList(data.getChildList());
            List<Long> nodeIds = nodeTreeInfoVos.stream().map(NodeTreeInfo::getId).collect(Collectors.toList());
            /*父节点id添加*/
            nodeIds.add(data.getId());
            /*查询每个节点分值*/
            Example example =new Example(HealthDeep.class);
            example.createCriteria().andIn("nodeId",nodeIds);
            List<HealthDeep> healthDeeps = healthDeepService.selectByExample(example);
            /*处理数据设置每个节点分值*/
            nodeTreeInfoVos.forEach(item ->{
                item.setChildList(null);
                item.setChildren(null);
                HealthDeep healthDeep = healthDeeps.stream().filter(f -> f.getNodeId().equals(item.getId())).findFirst().orElse(new HealthDeep());
                if(StringUtil.isNotBlank(healthDeep.getDataInfo())){
                    item.setOverallScore((int)Double.parseDouble(healthDeep.getDataInfo()));
                }
            });
            List<NodeTreeInfoVo> nodeTreeInfoVos1 = TreeUtil.toTree(data.getId(), nodeTreeInfoVos);
            /*父节点添加分值*/
            HealthDeep healthDeep = healthDeeps.stream().filter(f -> f.getNodeId().equals(data.getId())).findFirst().orElse(new HealthDeep());
            if(StringUtil.isNotBlank(healthDeep.getDataInfo())){
                data.setOverallScore((int)Double.parseDouble(healthDeep.getDataInfo()));
            }
            /*父节点设置子节点list*/
            data.setChildren(nodeTreeInfoVos1);
            /*处理数据为固定四列表格数据*/
            List<HealthReportVo> tableList = new ArrayList<>();
            dealTableData(data,tableList);
            /*曲线数据*/
            CurveVo curveVo = new CurveVo();
            List<HealthSituation> list = select(HealthSituation.builder().nodeId(nodeId).build());
            Map<Long, List<HealthSituation>> map = list.stream().collect(Collectors.groupingBy(HealthSituation::getMetricsId));
            HealthDeep deep = healthDeepService.getHealthDeep(nodeId).getData();
            healthCurve(deep, curveVo, map);
            /*返回给前端*/
            Map<String,Object> returnMap = new HashMap<>();
            returnMap.put("chart",curveVo);
            returnMap.put("tableList",tableList);
            return CheckResult.success(returnMap);

        }
        return CheckResult.fail(nodeTree.getCheckMsg());
    }

    /**
     * 处理为表格数据
     */
    private void dealTableData(NodeTreeInfoVo data,List<HealthReportVo> tableList) {
        if(data.getChildList() != null){
            for (NodeTreeInfoVo nodeTreeInfoVo : data.getChildList()) {
                String nodeTreeInfoVoScore = "暂无";
                if(nodeTreeInfoVo.getOverallScore() != null){
                    nodeTreeInfoVoScore = nodeTreeInfoVo.getOverallScore().toString();
                }
                if(nodeTreeInfoVo.getChildList() != null ){
                    for (NodeTreeInfoVo treeInfoVo : nodeTreeInfoVo.getChildList()) {
                        String treeInfoVoScore = "暂无";
                        if(treeInfoVo.getOverallScore() != null){
                            treeInfoVoScore = treeInfoVo.getOverallScore().toString();
                        }
                        if(treeInfoVo.getChildList() != null ){
                            for (NodeTreeInfoVo infoVo : treeInfoVo.getChildList()) {
                                String infoVoScore = "暂无";
                                if(infoVo.getOverallScore() != null){
                                    infoVoScore = infoVo.getOverallScore().toString();
                                }
                                HealthReportVo vo = HealthReportVo.builder().satelliteName(data.getName()+"("+data.getOverallScore()+")").fxtName(nodeTreeInfoVo.getName()+"("+nodeTreeInfoVoScore+")").qbjName1(treeInfoVo.getName()+"("+treeInfoVoScore+")").qbjName2(infoVo.getName()+"("+infoVoScore+")").build();
                                tableList.add(vo);
                            }
                        }else{
                            HealthReportVo vo = HealthReportVo.builder().satelliteName(data.getName()+"("+data.getOverallScore()+")").fxtName(nodeTreeInfoVo.getName()+"("+nodeTreeInfoVoScore+")").qbjName1(treeInfoVo.getName()+"("+treeInfoVoScore+")").qbjName2("").build();
                            tableList.add(vo);
                        }
                    }
                }else{
                    HealthReportVo vo = HealthReportVo.builder().satelliteName(data.getName()+"("+data.getOverallScore()+")").fxtName(nodeTreeInfoVo.getName()+"("+nodeTreeInfoVoScore+")").qbjName1("").qbjName2("").build();
                    tableList.add(vo);
                }
            }
        }else{
            String dataScore = "暂无";
            if(data.getOverallScore() != null){
                dataScore=data.getOverallScore().toString();
            }
            HealthReportVo vo = HealthReportVo.builder().satelliteName(data.getName()+"("+dataScore+")").fxtName("").qbjName1("").qbjName2("").build();
            tableList.add(vo);
        }
    }

    /**
     * 健康度曲线数据处理
     * 
     * @param healthDeep
     *            健康度数据
     * @param curveVo
     *            结果
     * @param map
     *            中间值
     */
    private void healthCurve(HealthDeep healthDeep, CurveVo curveVo, Map<Long, List<HealthSituation>> map) {
        if (BeanUtil.isNotEmpty(healthDeep)) {
            CurveYVo healthDeepData = new CurveYVo();
            healthDeepData.setName(healthDeep.getMetricsName());
            List<HealthSituation> list1 = map.get(healthDeep.getId());
            if (CollUtil.isNotEmpty(list1)) {
                list1.sort(Comparator.comparing(HealthSituation::getDataInfo));
                List<String> timeInfo = new ArrayList<>(list1.size());
                List<List<String>> dataInfo = new ArrayList<>();
                list1.forEach(x -> {
                    String time = DateUtil.format(x.getTimeInfo(), "yyyy-MM-dd");
                    if(StringUtil.isNotBlank(time)){
                        ArrayList<String> data = CollUtil.newArrayList(time, x.getDataInfo());
                        timeInfo.add(time);
                        dataInfo.add(data);
                    }
                });
                /*排序*/
                List<List<String>> sortList = dataInfo.stream().sorted(Comparator.comparing(i -> i.get(0))).collect(Collectors.toList());
                healthDeepData.setDataInfo(sortList);
                /*排序*/
                Collections.sort(timeInfo);
                curveVo.setHealthDeepTimeList(timeInfo);
                curveVo.setHealthDeepData(healthDeepData);
            }
        }
    }

    /**
     * 健康度曲线数据处理
     * 
     * @param functionalIndicators
     *            功能项数据
     * @param curveVo
     *            结果
     * @param map
     *            中间值
     */
    private void functionalCurve(List<FunctionalIndicators> functionalIndicators, CurveVo curveVo,
        Map<Long, List<HealthSituation>> map) {
        if (CollUtil.isNotEmpty(functionalIndicators)) {
            List<CurveYVo> functionalDataList = new ArrayList<>(functionalIndicators.size());
            for (FunctionalIndicators functionalIndicator : functionalIndicators) {
                CurveYVo curveYVo = new CurveYVo();
                curveYVo.setName(functionalIndicator.getMetricsName());
                List<HealthSituation> list2 = map.get(functionalIndicator.getId());
                if (CollUtil.isNotEmpty(list2)) {
                    list2.sort(Comparator.comparing(HealthSituation::getDataInfo));
                    List<String> timeInfo = new ArrayList<>(list2.size());
                    List<List<String>> dataInfo = new ArrayList<>();
                    list2.forEach(x -> {
                        String time = DateUtil.format(x.getTimeInfo(), "yyyy-MM-dd");
                        if(StringUtil.isNotBlank(time)){
                            ArrayList<String> data = CollUtil.newArrayList(time, x.getDataInfo());
                            timeInfo.add(time);
                            dataInfo.add(data);
                        }
                    });
                    /*排序*/
                    List<List<String>> sortList = dataInfo.stream().sorted(Comparator.comparing(i -> i.get(0))).collect(Collectors.toList());
                    curveYVo.setDataInfo(sortList);
                    /*排序*/
                    Collections.sort(timeInfo);
                    curveVo.setFunctionalTimeList(timeInfo);
                }
                functionalDataList.add(curveYVo);
            }
            curveVo.setFunctionalDataList(functionalDataList);
        }
    }

    /**
     * 健康度曲线数据处理
     * 
     * @param performanceIndicators
     *            性能项数据
     * @param curveVo
     *            结果
     * @param map
     *            中间值
     */
    private void performanceCurve(List<PerformanceIndicators> performanceIndicators, CurveVo curveVo,
        Map<Long, List<HealthSituation>> map) {
        if (CollUtil.isNotEmpty(performanceIndicators)) {
            List<CurveYVo> performanceDataList = new ArrayList<>(performanceIndicators.size());
            for (PerformanceIndicators performanceIndicator : performanceIndicators) {
                CurveYVo curveYVo = new CurveYVo();
                curveYVo.setName(performanceIndicator.getMetricsName());
                List<HealthSituation> list3 = map.get(performanceIndicator.getId());
                if (CollUtil.isNotEmpty(list3)) {
                    list3.sort(Comparator.comparing(HealthSituation::getDataInfo));
                    List<String> timeInfo = new ArrayList<>(list3.size());
                    List<List<String>> dataInfo = new ArrayList<>();
                    list3.forEach(x -> {
                        String time = DateUtil.format(x.getTimeInfo(), "yyyy-MM-dd");
                        if(StringUtil.isNotBlank(time)){
                            ArrayList<String> data = CollUtil.newArrayList(time, x.getDataInfo());
                            timeInfo.add(time);
                            dataInfo.add(data);
                        }
                    });
                    /*排序*/
                    List<List<String>> sortList = dataInfo.stream().sorted(Comparator.comparing(i -> i.get(0))).collect(Collectors.toList());
                    curveYVo.setDataInfo(sortList);
                    /*排序*/
                    Collections.sort(timeInfo);
                    curveVo.setPerformanceTimeList(timeInfo);
                }
                performanceDataList.add(curveYVo);
            }
            curveVo.setPerformanceDataList(performanceDataList);
        }
    }

    /**
     * 更新节点评分以及增加评分记录
     *
     * @param nodeId
     *            节点id
     * @param evaluationTime
     *            评估时间
     * @param result
     *            评估结果
     * @param healthDeep
     *            指标项
     */
    @Override
    public void insertInfo(Long nodeId, Date evaluationTime, Double result, HealthDeep healthDeep) {
        // 更新节点评分以及增加评分记录
        healthDeep.setTimeInfo(evaluationTime);
        healthDeep.setDataInfo(result.toString());
        healthDeep.setUpdatedTime(new Date());
        healthDeepService.updateById(healthDeep);

        HealthSituation healthSituation = new HealthSituation();
        healthSituation.setNodeId(nodeId);
        healthSituation.setMetricsId(healthDeep.getId());
        healthSituation.setMetricsName(healthDeep.getMetricsName());
        healthSituation.setMetricsType(3);
        healthSituation.setTimeInfo(evaluationTime);
        healthSituation.setDataInfo(result.toString());
        healthSituation.setCreatedTime(new Date());
        insert(healthSituation);
    }

}
